package com.share.web.servlet.common;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.share.commons.util.ConverterJSON;
import com.share.commons.web.weather.WeatherReport;
import com.share.web.servlet.base.BaseServlet;


public class WeatherServlet extends BaseServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response) ;
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		String city = request.getParameter("city") ;
		Map<Object, Object> map = new HashMap<Object, Object>() ;
		map.put("weather", WeatherReport.getWeather(city)) ;
		
		out.println(ConverterJSON.generate(map).toString()) ;
		
		out.flush();
		out.close();
	}

}
